import service from "@/utils/request"

// 文号记录

/**
 * 新增文号记录表
 */
export const saveDocNumRecordAPI = (data?: Object) => {
  return service({
    url: `/document/documentNumberRecord/save`,
    method: "post",
    data,
  })
}

/**
 * 选择断号
 */
export const getBrokenListAPI = (params?: Object) => {
  return service({
    url: `/document/documentNumber/queryBrokenList`,
    method: "get",
    params,
  })
}

/**
 * 获取列表
 * type:类别(RESERVED:预留文号, OFFLINE:线下占用,BROKEN:断号,CUSTOM:自定义文号,DEFAULT:系统生成)
 * */
export const getDocNumRecordListAPI = (params?: Object) => {
  return service({
    url: `/document/documentNumberRecord/list`,
    method: "get",
    params,
  })
}
/**
 * 获取文号列表 条件查询
 * */
export const getDocNumListAPI = (params?: Object) => {
  return service({
    url: `/document/documentNumber/list`,
    method: "get",
    params,
  })
}
/**
 * 获取流水号
 * */
export const getDocNumFlowRuleAPI = (params?: Object) => {
  return service({
    url: `/document/documentNumberFlowRule/page`,
    method: "get",
    params,
  })
}

/**
 * 公文字段
 */
export const getFormElementConfigList = () => {
  return service({
    url: `/formtemplate/form/formElementConfig/list`,
    method: "get",
  })
}

/**
 * 获取机构代字
 * */
export const getAgencyName = () => {
  return service({
    url: `/document/documentNumber/getAgencyName`,
    method: "get",
  })
}

/**
 * 根据机构代字获取年份
 * */
export const getYearByAgencyName = (name) => {
  return service({
    url: `/document/documentNumber/getYears/` + name,
    method: "get",
  })
}

/**
 * 获取文号
 * */
export const getDocNumAPI = (params?: Object) => {
  return service({
    url: `/document/documentNumberRecord/getNum`,
    method: "get",
    params,
  })
}

/**
 * 系统自动生成后用户修改文号调用
 * */
export const userUpdateDocNum = (data?: Object) => {
  return service({
    url: `/document/documentNumberRecord/userUpdateDocNum`,
    method: "post",
    data,
  })
}

interface checkDocParams {
  title: string //完整的文号名称
}
/**
 * 检查文号是否存在
 *
 * @param query 文号查询参数
 * @returns 返回请求响应
 */
export function checkDocNum(data: checkDocParams) {
  return service({
    url: "/document/documentNumberRecord/checkDocNum",
    method: "post",
    data,
  })
}

/**
 * 根据文种id获取机构代字
 * */
export const getDocNumListdata = (id) => {
  return service({
    url: `/document/documentType/getDocNumList/` + id,
    method: "get",
  })
}
